Date.prototype.format = function(fmt) {
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt)) {
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
    for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
    return fmt;
}

var vm = new Vue({
    el:"#ljw",
    data:{
        listPo:[],
        pageNum:1,
        pageSize:5,
        Dzt:"",
        quyu:"",
        nameId:"",




        total:0,
        //总页数
        pages:0,
        isFirstPage:false,
        isLastPage:false,
        hasPreviousPage:false,
        hasNextPage:false,
        //所有导航页号
        navigatepageNums:[],

        listck:[],
    },
    methods:{
        show(pageNum,pageSize){
            var json={
                pageNum:pageNum,
                pageSize:pageSize,
                id:this.nameId,
                orderStaId:this.Dzt,
                woseId:this.quyu
            }
            JSON.stringify(json)
            axios.post("/purchase/ListPo",json,{
                'Content-Type':'multipart/form-data'
            }).then(res=>{
                vm.listPo=res.data.obj.list
                console.log(vm.listPo)
                this.pageNum=parseInt(res.data.obj.pageNum);
                this.pageSize=parseInt(res.data.obj.pageSize);
                this.total=parseInt(res.data.obj.total);
                this.pages=parseInt(res.data.obj.pages);
                this.isFirstPage=res.data.obj.isFirstPage;
                this.isLastPage=res.data.obj.isLastPage;
                this.hasPreviousPage=res.data.obj.hasPreviousPage;
                this.hasNextPage=res.data.obj.hasNextPage;
                this.navigatepageNums=res.data.obj.navigatepageNums;
            }).catch(err=>{

            })
        },
        sc(pid){
            axios.get('/purchase/show1Po',{
                params:{
                    pid:pid
                }
            }).then(response=>{
                var dto=response.data
                if(dto.obj.orderStaId==1){
                    var i={
                        id:pid,
                        orderStaId:14
                    }
                    axios.post("/purchase/updaPo2",i,{

                    }).then(res=>{
                        alert("执行成功")
                        location.reload()
                    })
                }else{
                    var i={
                        id:pid,
                        orderStaId:14
                    }
                    axios.post("/purchase/updaPo2",i,{

                    }).then(res=>{


                        var crk={
                            relCode:pid,
                            pageNum:1,
                            pageSize:1,
                        }
                        JSON.stringify(crk)
                        axios.post('/wares/getStock_order',crk,{
                            'Content-Type':'multipart/form-data'
                        }).then(res=>{
                            vm.listck=res.data.obj.list
                            var code=vm.listck[0].code
                            var status=vm.listck[0].statusId
                            var single = vm.listck[0].single
                            var rk= {
                                bStatus: status,
                                status: 14,
                                code: code,
                                type: 21,
                                single: single,
                                subDate: new Date().format("yyyy-MM-dd hh:mm:ss"),
                                verifier: single,
                                verifyDate: new Date().format("yyyy-MM-dd hh:mm:ss"),
                            }
                            JSON.stringify(rk)
                            axios.post('/wares/nextStock_order',rk,{
                                'Content-Type':'multipart/form-data'
                            }).then(res=>{
                                alert("执行成功")
                                location.reload();
                            })

                        })


                    })
                }
            })

    },

        //上一页
        qian(){
            if(this.hasPreviousPage==true){
                // alert("上一页")s
                //表示有上一页
                this.show(this.pageNum-1,this.pageSize);
            }
        },
        //下一页
        hou(){
            if(this.hasNextPage==true){
                this.show(this.pageNum+1,this.pageSize);
            }
        },
        tiaozhuan(pid){
            localStorage.setItem("id",pid);
             // window.localhost.href="../purchase/查看采购单.html"
        }

    },
    mounted(){
        this.show(this.pageNum,this.pageSize)

    }
})











